Why javascript error stack for just one loop